package tx.yt.charge.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 日期工具类
 * Created by ZJ on 2014/12/3.
 */
public class DateUtil {
    public static final String SIMPLE_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static Date getCurrentDate() {
        return Calendar.getInstance().getTime();
    }

    public static String getDefaultFormatedDate() {
        Date date = getCurrentDate();
        SimpleDateFormat format = new SimpleDateFormat(SIMPLE_DATE_FORMAT);
        return format.format(date);
    }

    public static String getDefaultFormatedDate(String pattern) {
        Date date = getCurrentDate();
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        return format.format(date);
    }

    public static Date parseObject(Object obj) {
        Date date = getCurrentDate();
        try {
            SimpleDateFormat format = new SimpleDateFormat(SIMPLE_DATE_FORMAT);
            date = format.parse(obj.toString());
        } catch (Exception e) {
            e.fillInStackTrace();
        }
        return date;
    }
}